﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using CMISLibrary.Entities;
using CMISLibrary;
using ObjectDanhMuc.DB;

namespace ObjectDanhMuc
{
    public class cls_NPC_MENUOFUSER_Controller
    {
         #region   Atributes

	    //private DataSet CMIS_Header = new CMISOutputParameter();
	    private DataSet ds = new DataSet();
	    private DataTable dt = new DataTable();
	    private NPC_MENUOFUSER info;

	    #endregion

        #region   Constructor

	    public cls_NPC_MENUOFUSER_Controller()
	    {
		    info = new NPC_MENUOFUSER();
	    }
        public cls_NPC_MENUOFUSER_Controller(NPC_MENUOFUSER Info)
	    {
		    this.info = Info;
	    }

	    #endregion


        #region   Properties

        public NPC_MENUOFUSER pInfor
        {
            get { return info; }
            set { info = value; }
        }

        #endregion

        #region Method

        public IEnumerable<NPC_MENUOFUSER> select_NPC_MENUOFUSER_by_MENUOFUSERID(long longMENUOFUSERID)
        {
            try
            {
                var q = from p in CMIS2.DB.NPC_MENUOFUSER
                        orderby p.MENUOFUSERID ascending
                        where p.MENUOFUSERID == longMENUOFUSERID
                        select p;
                return q;
            }
            catch
            {
                CMIS2.ResetDB(); return null;
            }
        }

        public IEnumerable<NPC_MENUOFUSER> select_NPC_MENUOFUSER_by_USERID(string strSUBDIVISIONID, long longUSERID)
        {
            try
            {
                CMIS2.ResetDB();

                var q = from p in CMIS2.DB.NPC_MENUOFUSER
                        orderby p.MENUOFUSERID ascending
                        where p.SUBDIVISIONID == strSUBDIVISIONID && p.USERID == longUSERID
                        select p;
                return q;
            }
            catch
            {
                CMIS2.ResetDB(); return null;
            }
        }

        public bool insert_NPC_MENUOFUSER()
        {
            try
            {
                NPC_MENUOFUSER objNPC_MENUOFUSER = new NPC_MENUOFUSER()
                {
                    SUBDIVISIONID = info.SUBDIVISIONID,
                    MENUOFUSERID = info.MENUOFUSERID,
                    USERID = info.USERID,
                    MENUID = info.MENUID,
                    CREATEDDATE = info.CREATEDDATE,
                    CREATEDBY = info.CREATEDBY
                };
                CMIS2.DB.NPC_MENUOFUSER.InsertOnSubmit(objNPC_MENUOFUSER);
                CMIS2.DB.SubmitChanges();
                CMIS2.ResetDB();
                return true;
            }
            catch (Exception ex)
            {
                CMIS2.ResetDB(); return false;
            }
        }        

        public bool delete_NPC_MENUOFUSER(ref string strErr)
        {
            try
            {
                var query = from p in CMIS2.DB.NPC_MENUOFUSER where p.MENUOFUSERID == info.MENUOFUSERID && p.SUBDIVISIONID == info.SUBDIVISIONID select p;
                if (query != null && query.Count() > 0)
                {
                    CMIS2.DB.NPC_MENUOFUSER.DeleteAllOnSubmit(query.ToList());
                    CMIS2.DB.SubmitChanges();
                    return true;
                }
                return true;
            }
            catch (Exception ex)
            {
                strErr = ex.Message;
                CMIS2.ResetDB(); return false;
            }
        }

        #endregion

        #region SEQ

        public long GetNextSequence(ref string strErr)
        {

            try
            {

                //string strErr = "";
                long _ID = CMIS2.DB.ExecuteCommand("select seq_NPC_MENUOFUSER.nextval from dual", ref strErr);

                if (strErr == "") return _ID;

                else return -1;

            }

            catch
            {

                CMIS2.ResetDB(); return -1;
            }

        }
        
       

        #endregion 
    }
}
